import { ElMessageBox, ElMessage } from "element-plus";

//成功消息提示
export function succMsg(msg: any) {
  ElMessage({
    message: msg,
    grouping: true,
    type: "success"
  });
}

export function succAddmsg() {
  ElMessage({
    message: "新增成功",
    grouping: true,
    type: "success"
  });
}

export function succUpdatemsg() {
  ElMessage({
    message: "修改成功",
    grouping: true,
    type: "success"
  });
}

export function succDeletemsg() {
  ElMessage({
    message: "删除成功",
    grouping: true,
    type: "success"
  });
}

//失败消息提示
export function failMsg(msg: any) {
  ElMessage({
    message: msg,
    grouping: true,
    type: "error"
  });
}

export function failAddMsg(msg: any) {
  ElMessage({
    message: `新增失败，${msg}`,
    grouping: true,
    type: "error"
  });
}

export function failUpdateMsg(msg: any) {
  ElMessage({
    message: `修改失败，${msg}`,
    grouping: true,
    type: "error"
  });
}

export function failDeleteMsg(msg: any) {
  ElMessage({
    message: `删除失败，${msg}`,
    grouping: true,
    type: "error"
  });
}

//确认消息提示
export function confirm(msg: any, okFunc: any) {
  ElMessageBox.confirm(msg, "温馨提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning"
  })
    .then(() => {
      okFunc();
    })
    .catch((e: any) => {
      console.info(e);
      /*点击取消触发，需保留否则页面错误*/
    });
}

//确认消息提示
export function responseMsg(responseData: any, sucFunc?: any, failFunc?: any) {
  if (responseData.code == 200) {
    succMsg(responseData.msg);
    if (sucFunc != null && typeof sucFunc != "undefined") {
      sucFunc(responseData);
    }
  } else {
    //failMsg(responseData.msg)
    if (failFunc != null && typeof failFunc != "undefined") {
      failFunc(responseData);
    }
  }
}
